import { _decorator, Component, Node, sys } from 'cc';
import { loadRes } from './res/loadRes';
import { local, resPath } from './data/enmus';
import { load, save } from './untils/tools';
import { gameConfig } from './data/gameConfig';
import { wxAd } from './AD/wxAd';
const { ccclass, property } = _decorator;

@ccclass('mianTs')
export class mianTs extends Component {
    protected onLoad(): void {

    }
    start() {
        this.initData()
    }

    /**
     * 初始化数据
     */
    initData() {
        // 获取进入游戏时的时间(抖音插屏广告需要30秒后)
        gameConfig.goGameTime = new Date().getTime()
        // 判断当前平台
        gameConfig.system = sys.platform;
        // 音乐
        let isBgm = load(local.isBgm)
        if (isBgm == null) {
            isBgm = 1
            save(local.isBgm, isBgm)
        }
        gameConfig.isBgm = isBgm
        // 音效
        let isSound = load(local.isSound)
        if (isSound == null) {
            isSound = 1
            save(local.isSound, isSound)
        }
        gameConfig.isSound = isSound

        // 初始化音量
        if (gameConfig.isBgm) {
            gameConfig.bgmVol = 0.8
        } else {
            gameConfig.bgmVol = 0
        }
        if (gameConfig.isSound) {
            gameConfig.soundVol = 0.9
        } else {
            gameConfig.soundVol = 0
        }
        // 当前关卡
        let nowLevel = load(local.nowLevel)
        if (!nowLevel) {
            nowLevel = 1
            save(local.nowLevel, nowLevel)
        }
        gameConfig.nowLevel = nowLevel
        // 皮肤是否解锁
        let pifuIsJiesuo = load(local.pifuIsJiesuo)
        if (pifuIsJiesuo == null) {
            pifuIsJiesuo = 0
            save(local.pifuIsJiesuo, pifuIsJiesuo)
        }
        gameConfig.pifuIsJiesuo = pifuIsJiesuo
        // 当前使用的皮肤
        let nowPifu = load(local.nowPifu)
        if (nowPifu == null) {
            nowPifu = 1
            save(local.nowPifu, nowPifu)
        }
        gameConfig.nowPifu = nowPifu
    }
}


